<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/views/include/nocachehead.jsp"%>
<title>上传照片 - ${requestScope.album.albumName }</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/plugin/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/plugin/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/upload.js"></script>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/upload.css" >
</head>
<body>
	<div>
		<!-- main content start -->
		<div>
			<c:if test="${requestScope.message ne ''}">
				<c:out value="${requestScope.message}" />
			</c:if>
			<c:if test="${requestScope.album.activity eq 'UNDELETABLE'}">
				不能上传照片到头像相册
			</c:if>
		</div>
		返回<a href="${pageContext.request.contextPath}/attraction/feature/list/${requestScope.attractionId }.html">景点特色</a>
		<c:if test="${requestScope.album.activity ne 'UNDELETABLE'}">
		<div>
			<div id="photos-upload">
				<form action="${pageContext.request.contextPath}/attraction/feature/${requestScope.featureId }/buploadok/${requestScope.album.id }.html" method="post" id="upload">
					<input type="hidden" value="" id="uploadFiles" name="files"/>
					<div class="upload-list hidden">
						<div class="hd">
							<span class="name">照片</span> 
							<span class="size">大小</span>
							<span class="delete">删除?</span>
						</div>
						<div class="bd">
							<fieldset class="flash" id="fsUploadProgress"></fieldset>
						</div>
					</div>
					<div id="divStatus"></div>
					<div id="upload-btn"><span id="btn_holder"></span></div>
					<div class="upload-tips"></div>
					<div id="upload-status" class="hidden">
						<span class="num">共&nbsp;<b></b>&nbsp;张</span>
						<span class="continue-wrapper">&nbsp;|&nbsp;<a href="#" class="continue">继续添加照片</a></span> 
						<span class="total-size">总计：<b></b></span>
					</div>
					<div id="has-error" class="hidden">
						<b></b>张照片上传失败。&nbsp;
						<span class="nextstep hidden">&gt;&nbsp;<a href="#">继续下一步</a>？</span>
					</div>
					<div class="opt-btns hidden">
						<input type="button" id="upload-start" value="开始上传" class="btn-green" />
						<a id="btnCancel" href="#">取消上传</a>
					</div>
					<div class="message hidden" id="errMsg"></div>
					<noscript>
					<div class="message">您的浏览器不支持javascript，不能使用此页面的全部功能。
					请换用其他浏览器或者开启对javascript的支持。</div>
					</noscript>
					<div id="noflash" class="attn hidden">
						您没有安装flash播放器，或者您的flash版本不够，无法使用上传功能. 请安装最新版本的flashplayer.(<a
					href="http://fpdownload.macromedia.com/get/flashplayer/current/licensing/win/install_flash_player_10.exe">IE用户</a>/<a
					href="http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe">非IE用户</a>官方下载
					)</div>
					<input id="complete" type="submit" class="hidden minisubmit" value="&gt;&nbsp;下一步,填写图片信息" />
				</form>
				<div id="old-portal">
					<br />无法上传？<a href="${pageContext.request.contextPath}/attraction/feature/${requestScope.featureId }/upload/${requestScope.album.id }.html">使用普通方式上传照片</a>
				</div>
			</div>
		</div>
		</c:if>
		<!-- main content end -->
	</div>
	
	<script> 
	    var settings = {
	        debug: false,
	        flash_url: '${pageContext.request.contextPath}/plugin/swfupload/swfupload.swf',
	        file_post_name: 'file',
	        upload_url: '${pageContext.request.contextPath}/upload?method=batchUpload',
	        post_params: {
		        userid:	'${requestScope.attractionId }',
		        albumid: '${requestScope.album.id }'
		    },
	        file_size_limit: '',
	        file_types: '*.jpg; *.jpeg; *.gif; *.bmp; *.png',
	        file_types_description: 'Picture Files',
	        file_upload_limit: 20,
	        file_queue_limit: 0,
	        custom_settings: {
	            progressTarget: 'fsUploadProgress',
	            cancelButtonId: 'btnCancel',
	            startButtonId: 'btnStart',
	            delUrl: '${pageContext.request.contextPath}/upload?method=delUploaded'
	        },
	        button_placeholder_id: 'btn_holder',
	        button_width: 98,
	        button_height: 29,
	        button_image_url: '<%=request.getContextPath()%>/img/upload-btns.png',
	 
	        file_queued_handler: fileQueued,
	        file_queue_error_handler: fileQueueError,
	        file_dialog_complete_handler: fileDialogComplete,
	        upload_start_handler: uploadStart,
	        upload_progress_handler: uploadProgress,
	        upload_error_handler: uploadError,
	        upload_success_handler: uploadSuccess,
	        upload_complete_handler: uploadComplete,
	        queue_complete_handler: queueComplete,
	 
	        inimum_flash_version: '9.0.28',
	        swfupload_load_failed_handler: swfuploadLoadFailed
	    },
	 
	    oUploadBtn = $('#upload-btn'),
	    oUploadStatus = $('#upload-status'),
	    oStartUpload = $('#upload-start'),
	    oBtnCancel = $('#btnCancel'),
	    oOptBtns = $('.opt-btns'),
	    oUploadTips = $('.upload-tips'),
	    TMPL_UPLOAD_TIPS = '提示：每次最多可以<b>批量上传</b>二十张照片，按着&nbsp;“{CMD}”&nbsp;键可以一次选择多张照片';
	 
	    swfup = new SWFUpload(settings);
	    $('#uploadFiles').val('');
	    
	    oUploadBtn.show();
	 
	    // init tips
	    oUploadTips.html(TMPL_UPLOAD_TIPS.replace('{CMD}', navigator.userAgent.search('Mac') !== -1 ? 'Command' : 'Ctrl'));
	 
	    // cancel queue
	    oBtnCancel.click(function (e) {
	        e.preventDefault();
	        swfup.cancelQueue();
	        oOptBtns.addClass('hidden');
	        oUploadStatus.addClass('hidden');
	        oUploadBtn.removeAttr('style');
	        
	        var url = '${pageContext.request.contextPath}/attraction/feature/${requestScope.featureId }/buploadok/${requestScope.album.id }.html';
		    var files = $("#uploadFiles").val();
	        doAjax(url, "files="+files, function(json){
	        	try {
	        		var msg = "压缩遇到未知错误！";
					if(!json.success) {
						if(json && !json.logined) {
							alert('请先登录！');
							window.location = '${pageContext.request.contextPath}/login.html';
							return false;
						}
						msg = json.errmsg;
					} else {
						$('#errMsg').hide();
						return;
					}
					$('#errMsg').html(msg).show();
					setTimeout(function () {
						$('#errMsg').hide();
			        }, $.browser.msie ? 1200 : 800);
	        	} catch(e) {
	        		$('#errMsg').html("压缩遇到未知错误！").show();
					setTimeout(function () {
						$('#errMsg').hide();
						window.location = okUrl;
			        }, $.browser.msie ? 1200 : 800);
		        }
		    }, 
		    function(){
		    	$('#errMsg').html("压缩遇到未知错误！").show();
				setTimeout(function () {
					$('#errMsg').hide();
		        }, $.browser.msie ? 1200 : 800);
		    	oStartUpload.val('开始上传').removeAttr('disabled');
			}, 
		    function(){
		    	oStartUpload.val('压缩中...').attr('disabled','disabled');
			},
			function(){
				oStartUpload.val('开始上传').removeAttr('disabled');
			});
		
	        oStartUpload.val('开始上传').removeAttr('disabled');
	        setTimeout(function () {
	            oUploadTips.removeClass('hidden');
	        }, $.browser.msie ? 1200 : 800);
	    });
	 
	    // start upload 
	    oStartUpload.click(function () {
	        swfup.startUpload();
	    });
	 
	    // continue upload
	    oUploadStatus.find('.continue').click(function (e) {
	        e.preventDefault();
	        oUploadBtn.removeAttr('style');
	        oUploadStatus.addClass('hidden');
	    });
	 
	    $('.nextstep a').click(function (e) {
	        e.preventDefault();
	        $('#upload').submit();
	    });

	    $("#upload").submit(function(){
	    	$('#errMsg').html("图片正在压缩中，请等待...").show();
		    var url = '${pageContext.request.contextPath}/attraction/feature/${requestScope.featureId }/buploadok/${requestScope.album.id }.html';
		    var files = $("#uploadFiles").val();
		    var okUrl = '${pageContext.request.contextPath}/attraction/feature/uploadok/${requestScope.featureId }/${requestScope.album.id }.html';
		    $.post(url,"files="+files,function(json){
			    try {
					var msg = "压缩遇到未知错误！"
					if(json && !json.success) {
						if(json && !json.logined) {
							alert('请先登录！');
							window.location = '${pageContext.request.contextPath}/login.html';
							return false;
						}
						msg = json.errmsg;
					} else if(json) {
						window.location = okUrl;
						return;
					}
					$('#errMsg').html(msg).show();
					setTimeout(function () {
						$('#errMsg').hide();
						window.location = okUrl;
			        }, $.browser.msie ? 1200 : 800);
			    } catch(e) {
			    	$('#errMsg').html(msg).show();
					setTimeout(function () {
						$('#errMsg').hide();
						window.location = okUrl;
			        }, $.browser.msie ? 1200 : 800);
				}
				
			});
			return false;
		});
	</script> 
	
</body>
</html>